package net.huashitong.synthetical.newSupervision.service;

import com.sirdc.modules.core.dao.BaseDao;
import com.sirdc.modules.core.service.BaseService;
import com.sirdc.modules.core.service.StringService;
import com.sirdc.modules.core.web.model.Message;
import com.sirdc.modules.sys.base.StringPKService;
import com.sirdc.modules.sys.entity.SysDept;
import com.sirdc.modules.sys.entity.SysLogin;
import com.sirdc.modules.sys.entity.SysUser;
import com.sirdc.modules.sys.service.SysDeptService;
import com.sirdc.modules.sys.service.SysLoginService;
import com.sirdc.modules.sys.service.SysUserService;
import com.sirdc.modules.sys.util.SysUserUtils;
import com.sirdc.modules.sys.util.UserUtils;
import com.sirdc.modules.utils.ObjectUtils;
import com.sirdc.modules.utils.StringUtils;
import net.huashitong.synthetical.newSupervision.dao.TaskSendDao;
import net.huashitong.synthetical.newSupervision.entity.TaskNew;
import net.huashitong.synthetical.newSupervision.entity.TaskSend;
import net.huashitong.synthetical.newSupervision.filter.TaskNewFilter;
import net.huashitong.synthetical.newSupervision.filter.TaskSendFilter;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: ling
 * Date: 2019/7/31
 * Time: 10:27
 * To change this template use File | Settings | File /appTaskMain/allTaskMainTemplates.
 * Description:
 */
@Service
public class TaskLeaderService extends StringPKService<TaskSend> {

    @Autowired
    private TaskSendService taskSendService;
    @Autowired
    private SysUserService userService;
    @Autowired
    private SysLoginService loginService;
    @Autowired
    private SysDeptService sysDeptService;
    @Override
    protected BaseDao<TaskSend, String> getDao() {
        return null;
    }

    /**
     * 县领导批转任务
     * @param filter
     * @return
     */
    public String endorseTask(TaskSendFilter filter){
        //县领导任务
        TaskSend taskSend = taskSendService.getById(filter.getSysId());
        //将传过来的 条件复制给新任务,由新的单位接收任务
        taskSend.setUserId(filter.getUserId());
        //当前登录用户userid
        String userId = SysUserUtils.getUserId();
        //查询承办人单位
        SysLogin login = loginService.getById(filter.getUserId());
        String deptId = login.getDeptId();
        SysDept dept = sysDeptService.getById(deptId);
        taskSend.setDepartName(dept.getDeptName());
        //设置批转领导id
        taskSend.setPersonId(userId);
        taskSend.setPerson(userService.getById(userId).getName());
        //从新设置任务状态为未签收
        taskSend.setType("0");
        //更新任务
        taskSendService.update(taskSend);
        return  "200";
    }

    /**
     * 县领导批量签收任务
     * @param id
     * @return
     */
    public String signSends(List<String> id) {
        for (String s : id) {
            TaskSend taskSend = taskSendService.getById(s);
            taskSend.setType("1");
            taskSendService.update(taskSend);
        }
        return "200";
    }
}
